import java.awt.*;
import java.awt.event.*;

public class Menus extends Frame implements ActionListener{

      Button b1, b2, b3;
      Order order;

      public Menus() {

            setLayout(new GridLayout(2,1));

            setSize(200,200);
            setVisible(true);

            Panel bPanel = new Panel();
            order = new Order();

            b1 = new Button("Create");
            b2 = new Button("View");
            b3 = new Button("Submit");

            b1.addActionListener(this);
            b2.addActionListener(this);
            b3.addActionListener(this);

            bPanel.setLayout(new GridLayout(1,3));
            bPanel.add(b1);
            bPanel.add(b2);
            bPanel.add(b3);

            addWindowListener(new WindowCloser());
      
            add(new Label("Menuing System"));
            add(bPanel);
            pack();
      }

      public void actionPerformed(ActionEvent e) {
            if(e.getSource() == b1) {
                  new createFrame();            
            }
            else if(e.getSource() == b2) {
                  new viewFrame();
            }
            else if(e.getSource() == b3) {
                  new submitFrame();
            }
        }


      public static void main(String[] args) {
            
            Menus myMenu = new Menus();
      }

      // Inner class!
      class createFrame extends Frame implements ActionListener {

      TextField name, address, account, stocknum, quantity;
      Button okay, cancel;

            public createFrame() {

                  setSize(200, 400);
                  setLayout(new GridLayout(6,2));
                  setVisible(true);
            
                  name = new TextField();
                  address = new TextField();
                  account = new TextField();
                  stocknum = new TextField();
                  quantity = new TextField();

                  okay = new Button("OK");
                  cancel = new Button("CANCEL");

                  okay.addActionListener(this);
                  cancel.addActionListener(this);
      
                  add(new Label("Name"));
                  add(name);
                  add(new Label("Address"));
                  add(address);
                  add(new Label("Account"));
                  add(account);
                  add(new Label("Stock #"));
                  add(stocknum);
                  add(new Label("Quantity"));
                  add(quantity);
                  add(okay);
                  add(cancel);
                        
                  addWindowListener(new WindowCloser());

                  pack();
            }

            public void actionPerformed(ActionEvent e) {
                  if(e.getSource() == okay) {
                        order.name = name.getText();
                        order.address = address.getText();
                        order.account = account.getText();
                        order.stock = stocknum.getText();
                        order.quantity = quantity.getText();
                        setVisible(false);
                        dispose();
                  }
                  else if(e.getSource() == cancel) {
                        setVisible(false);
                        dispose();
                  }
            }            
      }


      // inner class!
      class viewFrame extends Frame {
      
            public viewFrame() {    

                  addWindowListener(new WindowCloser());

                  setSize(200, 400);
                  setVisible(true);

                  TextArea text = new TextArea("\nName:\t"+order.name +
                                   "\naddress:\t"+order.address +
                                   "\naccount:\t"+order.account +
                                   "\nstock:\t"+order.stock +
                                   "\nquantity:\t"+order.quantity);
                  add(text);
                  pack();
            }
      }

      // inner class!
      class submitFrame extends Frame {

            public submitFrame() {
                  addWindowListener(new WindowCloser());

                  setSize(200,400);
                  setVisible(true);
                  add(new Label("submitting order"));
                  pack();
            }
      }
}

class Order extends Object {
      public String name, address, account, stock, quantity;

      public Order() {
            name = new String();
            address = new String();
            account = new String();
            stock = new String();
            quantity = new String();
      }

      public String toString() {
            return(name+"\n"+address+"\n"+account+"\n"+stock+"\n"+quantity);
      }
}      

class WindowCloser extends WindowAdapter {
      public void windowClosing(WindowEvent e) {
            Window win = e.getWindow();
            win.setVisible(false);
            win.dispose();
      }
}
